<template>
	<view class="container">
		<view class="header-box flex-column">
			<view class="header flex-column">
				<view class="header-item flex-row">
					<view class="header-item-child flex-row">我的钱包</view>
					<view class="header-item-child flex-row child-btn">
						<button @tap.stop="jump('/pages/user/wallet/withdrawal')">提现</button>
						<button class="recharge" @tap.stop="jump('/pages/user/wallet/recharge')">充值</button>
					</view>
				</view>
				<view class="header-item flex-row">
					<view class="header-item-child money-box flex-column" style="border-right: 1px solid #fff;">
						<view class="header-item-child-view money-tip">余额（元）</view>
						<view class="header-item-child-view money-num">{{userInfo.wallet}}</view>
					</view>
					<view class="header-item-child money-box flex-column" style="padding-left: 20rpx;">
						<view class="header-item-child-view money-tip">冻结金额（元）</view>
						<view class="header-item-child-view money-num">{{userInfo.freeze_wallet}}</view>
					</view>
				</view>
			</view>
			<view class="header-item tab-box flex-row">
				<view class="tab flex-column" :class="index == 0 ? 'tab-active' : ''" @tap.stop="checkTab(0)">
					余额明细（元）<view class="fot"></view>
				</view>
				<view class="tab flex-column" :class="index == 1 ? 'tab-active' : ''" @tap.stop="checkTab(1)">
					充值记录（元）<view class="fot"></view>
				</view>
			</view>
		</view>

		<view class="body">
			<!-- <view class="tab-box flex-row">
				<view class="tab flex-column tab-active">
					余额明细<view class="fot"></view>
				</view>
				<view class="tab flex-column">
					充值记录<view class="fot"></view>
				</view>
			</view> -->
			<view class="data-list flex-column">
				<!-- <scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll"
					:scroll-top="tabScrollTop"> -->
				<block v-for="(item,index) in list" :key="index">
					<view class="list-item flex-row" v-if="item.wallet > 0">
						<view class="item-type type-red">{{item.money_type}}</view>
						<view class="item-type flex-row">
							<view class="type-red" style="margin-right: 100rpx;">{{item.wallet}}</view>
							<view class="type-date type-red">{{item.money_date}}</view>
						</view>
					</view>
					<view class="list-item flex-row" v-else>
						<view class="item-type">{{item.money_type}}</view>
						<view class="item-type flex-row">
							<view style="margin-right: 100rpx;">{{item.wallet}}</view>
							<view class="type-date">{{item.money_date}}</view>
						</view>
					</view>
				</block>
				<!-- </scroll-view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				index: 0,
				requestIng: false,
				page: 1,
				list: []
			}
		},
		computed: {
			...mapGetters(['userInfo'])
		},
		onLoad() {

		},
		onShow() {
			this.init()
		},
		methods: {
			jump(url) {
				this.$util.jump(url)
			},
			init() {
				this.page = 1;
				this.index = 0;
				this.getList(1)
			},
			checkTab(index) {
				console.log(index)
				this.index = index;
				this.page = 1;
				this.getList(this.page)
			},
			async getList(page) {
				let that = this;
				that.page = page
				let requestData = {
					page: page
				};
				if (page == 1) {
					uni.pageScrollTo({
						scrollTop: 0,
						duration: 300
					});
				}
				let url = that.index == 1 ? 'money.rechargeLog' : 'money.walletLog';
				that.$util.loading('加载中');
				return new Promise((resolve, reject) => {
					that.$http(url, requestData).then(async res => {
							console.log('记录列表', res)
							that.requestIng = false
							uni.hideLoading()
							if (res.code === 1) {
								if (requestData.page == 1) {
									that.list = res.data
								} else {
									that.list = that.list.concat(res.data)
								}
								if (res.data?.length > 0) {
									console.log('页码增加')
									that.page = that.page + 1
								}
								resolve(res.data);
							} else {
								resolve(false);
							}
						})
						.catch(async err => {
							that.requestIng = false
							uni.hideLoading()
							resolve(false);
						})
				});
			},
		},
		/**
		 * 上拉加载
		 */
		onReachBottom() {
			console.log('onReachBottom');
			!this.requestIng && (this.requestIng = true, this.getList(this.page))
		},
	}
</script>

<style lang="scss">
	.container {
		background: #eee;
		min-height: 100vh;

		.flex-column {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
		}

		.flex-row {
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.header-box {
			width: 100vw;
			height: 400rpx;
			position: fixed;
			z-index: 100;
			top: 0;
			left: 0;


			.header {
				background: #FF9000;
				height: 300rpx;
				width: 100%;
				color: #fff;
				justify-content: flex-start;

				&-item {
					width: 86%;
					justify-content: space-between;
					height: 130rpx;

					&-child {
						font-size: 40rpx;
						font-weight: 600;
					}

					.child-btn {
						width: 50%;
						justify-content: space-between;

						button {
							border: 1px solid #fff;
							border-radius: 50rpx;
							width: 130rpx;
							height: 60rpx;
							font-weight: 400;
						}

						.recharge {
							background: #fff;
							color: #FF9000;
						}
					}
				}

				.money-box {
					flex: 1;
					align-items: flex-start;
					box-sizing: border-box;
					height: 100%;
					justify-content: space-around;

					.money-tip {
						font-size: 24rpx;
						font-weight: 400;
					}

					.money-num {
						font-size: 50rpx;
					}
				}
			}

			.tab-box {
				color: #666;
				background: #fff;
				height: 100rpx;
				width: 100%;

				.tab {
					flex: 1;
					height: 100%;
				}

				.tab-active {
					color: #333;
					font-size: 36rpx;
					font-weight: 700;

					.fot {
						width: 60rpx;
						height: 4px;
						background: #FF9000;
						margin-top: 10rpx;
					}
				}
			}
		}

		.body {
			// background: red;
			// top: 400rpx;
			// border-radius: 20px 20px 0 0;
			// height: 70vh;
			width: 100vw;
			margin-top: 400rpx;
			background: #fff;
			// position: absolute;

			/* .tab-box {
				color: #666;
				background: #fff;
				height: 100rpx;

				.tab {
					flex: 1;
					height: 100%;
				}

				.tab-active {
					color: #333;
					font-size: 36rpx;
					font-weight: 700;

					.fot {
						width: 60rpx;
						height: 4px;
						background: #FF9000;
						margin-top: 10rpx;
					}
				}
			} */
			.data-list {
				background: #fff;
				width: 90%;
				margin: 0 5% 0 5%;

				.list-item {
					height: 100rpx;
					width: 100%;
					border-bottom: 1px solid #eee;
					justify-content: space-between;

					.item-type {
						font-size: 26rpx;
						color: #333;
					}

					.type-date {
						font-size: 26rpx;
						color: #999;
					}

					.type-red {
						color: #FF9000;
					}


				}

			}
		}
	}
</style>
